package cn.powerone.scm.controller;

import java.util.List;

import cn.powerone.scm.pojo.bo.ScmProjectCommonReq;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmInventoryLog;
import cn.powerone.scm.service.IScmInventoryLogService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author PowerOne
 * @date 2025-08-21
 */
@RestController
@RequestMapping("/scm/log")
public class ScmInventoryLogController extends BaseController
{
    @Autowired
    private IScmInventoryLogService scmInventoryLogService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('scm:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmInventoryLog scmInventoryLog)
    {
        startPage();
        List<ScmInventoryLog> list = scmInventoryLogService.selectScmInventoryLogList(scmInventoryLog);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('scm:log:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmInventoryLog scmInventoryLog)
    {
        List<ScmInventoryLog> list = scmInventoryLogService.selectScmInventoryLogList(scmInventoryLog);
        ExcelUtil<ScmInventoryLog> util = new ExcelUtil<ScmInventoryLog>(ScmInventoryLog.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmInventoryLogService.selectScmInventoryLogById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('scm:log:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmInventoryLog scmInventoryLog)
    {
        return toAjax(scmInventoryLogService.insertScmInventoryLog(scmInventoryLog));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('scm:log:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmInventoryLog scmInventoryLog)
    {
        return toAjax(scmInventoryLogService.updateScmInventoryLog(scmInventoryLog));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('scm:log:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmInventoryLogService.deleteScmInventoryLogByIds(ids));
    }

    /**
     * 基于projectID查询【进出货记录】列表
     */
    @PreAuthorize("@ss.hasPermi('scm:log:list')")
    @GetMapping("/listByProject")
    public TableDataInfo listByProject(ScmProjectCommonReq scmProjectCommonReq)
    {
        startPage();
        List<ScmInventoryLog> list = scmInventoryLogService.selectScmInventoryLogListByProject(scmProjectCommonReq);
        return getDataTable(list);
    }
    /**
     * 基于客户或者供应商查询【进出货记录】列表
     */
    @PreAuthorize("@ss.hasPermi('scm:log:list')")
    @GetMapping("/listByCustomer")
    public TableDataInfo listByCustomer(ScmProjectCommonReq scmProjectCommonReq){
        startPage();
        scmProjectCommonReq.setChangeType(2L);
        List<ScmInventoryLog> list = scmInventoryLogService.selectScmInventoryLogListByCustomerOrSupplier(scmProjectCommonReq);
        return getDataTable(list);
    }
    /**
     * 基于客户或者供应商查询【进出货记录】列表
     */
    @PreAuthorize("@ss.hasPermi('scm:log:list')")
    @GetMapping("/listBySupplier")
    public TableDataInfo listBySupplier(ScmProjectCommonReq scmProjectCommonReq){
        startPage();
        scmProjectCommonReq.setChangeType(1L);
        List<ScmInventoryLog> list = scmInventoryLogService.selectScmInventoryLogListByCustomerOrSupplier(scmProjectCommonReq);
        return getDataTable(list);
    }
}
